<!-- 案场列表右侧 -->
<template>
  <div class='crimeSceneList_right_content'>
    <dt-info ref="info" :options="options" :info="searchInfo">
    </dt-info>
    <Tabs ref="nav" type="card" v-model="tabsVal" :animated="false"
      :on-click="changetab(tabsVal)">
      <TabPane class="tab_pane" label="全部案场" name="allBuild" ref="TabPane">
        <all-build ref="allBuild" :onresizeHeight='onresizeHeight'
          @changeStarStatus='changeStarStatus' />
      </TabPane>

      <TabPane label="关注案场" name="followBuild">
        <follow-build ref="FollowBuild" :onresizeHeight='onresizeHeight'
          @changeStarStatus='changeStarStatus' />
      </TabPane>
    </Tabs>
    <div class="syBtn" v-if="orgFlag==2">
      <span v-if="unlocking('0114020000')">
        <Icon type="ios-alert" size='20' color='#999' />提示：当前有{{caseNum}}个案场无归属事业处<em
          @click="goAdjust">立即查看</em>
      </span>
      <Button type="info" style="margin-left:10px;" @click="goCaseRecord"
        v-if="unlocking('0114010000')">查看调整记录</Button>
      <Button type="primary" style="margin-left:10px;" v-if="unlocking('0114020000')"
        @click="goAdjustmentCase">调整案场所属</Button>
    </div>
    <div class="syBtn" v-else-if="noOrgNum > 0 && unlocking('0114030000')">
      <span>
        <Icon type="ios-alert" size='20' color='#999' />提示：当前有{{noOrgNum}}个案场无归属业务组织<em
          @click="onCheckNoOrg">立即查看</em>
      </span>
    </div>
  </div>
</template>

<script>
  import store from '@/store'
  import { buildPage } from '@/router/buildPage.js'
  import FollowBuild from './component/followBuild.vue'
  import allBuild from './component/allBuild.vue'
  import caseMgr from '@/biz/crimeSceneList'
  import orgMgr from '@/biz/organizationManagement/organizationManagement'
  import searchOpt from './opt/listSearch'
  import dt from '@dt/dt'

  export default {
    components: {
      FollowBuild,
      allBuild,
    },
    props: {
      treeList: {
        type: Array,
        default: () => [],
      },
    },
    watch: {
      tabsVal(val, oldVal) {
        if (val != oldVal) {
          this.saveTableDatail()
        }
      }
    },
    data() {
      return {
        onresizeHeight: 0,
        options:[],
        searchInfo:{
          userId:dt.userInfo().userId,
          housesName: '',
          salesManager: '',
          cityId: [],
          status: '',
          cooperationMode: '',
        },
        tabsVal: '',
        orgFlag: '2', //组织架构切换(1: OA 2: 业务) 
        listOrgId: '',
        caseNum: '',
        noOrgNum: 1
      }
    },
    methods: {
      goCaseRecord() {
        this.$router.push({
          path: '/home/caseRecord',
        })
      },
      goAdjustmentCase() {
        this.$router.push({
          path: '/home/adjustmentCase',
        })
      },
      goAdjust() {
        this.$router.push({
          path: '/home/adjustmentCase',
          query: {
            noOrg: true
          }
        })
      },
      onCheckNoOrg() {
        this.getOrgId(this.listOrgId, this.orgFlag, 1, true)
      },
      init() {
        this.$nextTick(() => {
          this.onresizeHeight = window.innerHeight - 48 - 320
        })
      },
      changeLeftBar() {
        store.dispatch('setRouterList', buildPage)
        this.$router.push({
          path: '/buildingHome/statistics',
        })
      },
      //重置
      clearForm() {
        this.$refs.info.resetFields()
        this.searchInfo = {
          userId:dt.userInfo().userId,
          housesName: '',
          salesManager: '',
          cityId: [],
          status: '',
          cooperationMode: '',
        }
        this.getOrgId(this.listOrgId, this.orgFlag, 1)
      },
      //搜索
      saveTableDatail() {
        this.getOrgId(this.listOrgId, this.orgFlag, 1)
      },
      getOrgId(orgId, orgFlag, pageNum, notOrg = false) {
        this.orgFlag = orgFlag
        this.listOrgId = orgId
        if (this.orgFlag == 1) {
          orgMgr.getNoJyOfficeNum(this.listOrgId.caseLocationId).then(res => {
            this.noOrgNum = res
          })
        }

        this.$refs.allBuild.getBuildList(
          this.listOrgId,
          this.searchInfo,
          pageNum,
          this.orgFlag,
          notOrg,
        )
        this.$refs.FollowBuild.getBuildList(
          this.listOrgId,
          this.searchInfo,
          pageNum,
          this.orgFlag,
          notOrg,
        )
      },
      // 获取无事业处案场
      getNoOfficeNum(data) {
        console.log(data, '穿过来的业务组织');
        let parmas = {
          level: data.level,
          orgId: data.orgId,
          userId: this.$dt.userInfo().userId,
        }
        caseMgr.getNoOfficeNum(parmas).then(res => {
          console.log(res, '案场数量');
          this.caseNum = res
        })
      },

      changetab(name) {
        if (!this.listOrgId) {
          return false
        }
      },
      //取消关注或加入关注
      changeStarStatus(val) {
        console.log(val, '点击了取消关注或加入关注')
        this.$refs.allBuild.getBuildList(this.listOrgId, this.searchInfo, '', this.orgFlag)
        this.$refs.FollowBuild.getBuildList(this.listOrgId, this.searchInfo, '', this
          .orgFlag)
      }
    },
    created() {
      document.onkeydown = (e) => {
        if (e.keyCode == 13 && this.$route.path == '/home/crimeSceneList') {
          this.saveTableDatail()
        }
      }
    },
    activated() {
      if (this.$refs.TabPane.$el) {
        this.onresizeHeight =
          window.innerHeight - this.$refs.TabPane.$el.offsetTop - 320
      }
      window.onresize = () => {
        return (() => {
          setTimeout(() => {
            if (this.$refs.TabPane.$el) {
              this.onresizeHeight = window.innerHeight - 48 - 320
            }
          }, 10)
        })()
      }
    },
    mounted() {
      this.options = new searchOpt(this).options()
      this.init()
      window.onresize = () => {
        return (() => {
          setTimeout(() => {
            if (this.$refs.TabPane.$el) {
              this.onresizeHeight = window.innerHeight - 48 - 320
            }
          }, 10)
        })()
      }
    },
  }
</script>
<style lang='scss' scoped>
  .crimeSceneList_right_content {
    position: relative;

    ::v-deep .ivu-tabs-bar {
      padding-left: 20px;
    }

    .syBtn {
      position: absolute;
      left: 205px;
      top: 115px;
      display: flex;
      flex-direction: row;

      span {
        line-height: 32px;

        background: rgba(254, 252, 236, 1);
        padding: 0 20px;

        em {
          font-style: normal;
          color: #19be6b;
          display: inline-block;
          margin-left: 5px;
          cursor: pointer;
        }
      }

    }
  }

  .house_search {
    ::v-deep .ivu-select-dropdown-list {
      max-height: 300px;
      overflow-y: auto;
    }
  }
</style>